import type {SocketStatus} from '@/store/modules/system/type'

export const useSystemStore = defineStore({
  id: 'systemStore',
  state: () => ({
    version: '' as string, //版本号
    primaryColor: '#f4756b' as string, //主题颜色
    windowWidth: 0 as number, //窗口宽度
    windowHeight: 0 as number, //窗口高度
    navigationHeight: 0 as number, //导航栏高度
    navigationTop: 0 as number, //导航栏距离顶部的距离
    navBtnWidth: 0 as number, //胶囊按钮宽度
    navBtnMarginX: 0 as number, //胶囊按钮X轴外边距
    topAreaHeight: 0 as number, //顶部区域总高度（包括状态栏和导航栏）
    socketStatus: -1 as SocketStatus //Socket的状态
  }),
  getters: {},
  actions: {
    getSystemInfo() {
      const {windowWidth, windowHeight, appVersion} = uni.getSystemInfoSync()
      const {width, height, top, right} = uni.getMenuButtonBoundingClientRect()
      this.windowWidth = windowWidth
      this.windowHeight = windowHeight
      this.version = appVersion ?? ''
      this.navigationHeight = height + top + windowWidth - right
      this.navigationTop = top
      this.navBtnWidth = width
      this.navBtnMarginX = windowWidth - right
      this.topAreaHeight = height + top
    }
  }
})
